{% extends "smErp/base.html" %}

{% block css_style %}
    {% load staticfiles %}
    <link href="{% static 'smErp/css/brand_info.css' %}" type="text/css" rel="stylesheet">

{% endblock %}



{% block content %}
    <div class="inner wrp">
        <div class="page_nav">
            <a href="{% url 'smErp:manage' %}" class="jsUrlLink" data-url="{% url 'smErp:manage' %}" target="_self">管理中心</a>
            <span class="gap">/</span>
            查看品牌
        </div>

        {# 品牌头 #}
        <div class="brand_box">
            <div id="logo">
                <img src="{{ brand.logo }}">
            </div>
            <label id="brand_name">{{ brand.name_zh }}</label>
            <a id="brand_del" href="javascript:void(0);" data-url="{% url 'smErp:brand_info' brand.id%}" class="btn js_create jsUrlLink btn_primary" target="_self" onclick="delete_brand(this)">
                <span>删除</span>
            </a>
        </div>

        {# 品牌信息  #}
        <div class="container_box cell_layout">
            <div class="brand-title" id="brand_title">
                <h1>基本信息</h1>
                <a href="{% url "smErp:brand_change" brand.id%}" data-url="{% url "smErp:create_brand" %}" class="btn js_create jsUrlLink btn_primary" target="_self">
                    <span>修改</span>
                </a>
            </div>
            <div class="main_bd">
                <div class="meta_content info_box">
                    <div class="frm_control_group show_value">
                        <label for="" class="frm_label">品牌名称</label>
                        <div class="frm_controls frm_vm_pt">
                            <span class="frm_input_box" name="name">{{ brand.name_zh }}</span>
                        </div>
                    </div>
                    <div class="frm_control_group show_value">
                        <label for="" class="frm_label">英文名称</label>
                        <div class="frm_controls frm_vm_pt">
                            <span class="frm_input_box" name="name">{{ brand.name_en }}</span>
                        </div>
                    </div>
                    <div class="frm_control_group show_value">
                        <label for="" class="frm_label">商标logo</label>
                        <div class="frm_controls frm_vm_pt">
                            <span class="frm_input_box" name="logo">
                                <img style="width: 100px; height: 100px;" src="{{ brand.logo }}">
                            </span>
                        </div>
                    </div>
                    <div class="frm_control_group show_value">
                        <label for="" class="frm_label">品牌描述</label>
                        <div class="frm_controls frm_vm_pt">
                            <span class="frm_input_box" name="phone">{{ brand.description }}</span>
                        </div>
                    </div>
                    <div class="frm_control_group show_value">
                        <label for="" class="frm_label">商标证书</label>
                        <div class="frm_controls frm_vm_pt">
                            {% if brand.license_img %}
                                {% for i in brand.license_img_as_list %}
                                    <span class="frm_input_box" name="license_img">
                                        <img style="width: 700px; height: 400px;" src="{{ i }}">
                                    </span>
                                {% endfor %}
                            {% endif %}
                        </div>
                    </div>
                </div>

            </div>
        </div>

        {# 证书列表 #}
        <div class="container_box cell_layout">
            <div class="brand-title" id="brand_title">
                <h1>品牌认证</h1>
                <a href="{% url "smErp:brand_license" brand.id%}?action=create" data-url="{% url "smErp:brand_license" brand.id%}?action=create" class="btn js_create jsUrlLink btn_primary" target="_self">
                    <span>添加</span>
                </a>
            </div>
                <div class="table_wrp app_list">
                    <table class="table js_draft" id="draft_tb" cellspacing="0">
                        <thead class="thead">
                            <tr>
                                <th class="table_cell content">证书名称</th>
                                <th class="table_cell content">证书图片</th>
                                <th class="table_cell content">类型</th>
                                <th class="table_cell opr">操作</th>
                            </tr>
                        </thead>
                        <tbody class="tbody" id="draftlists">
                        {% if brand.smerpbrandlicense_set.all %}
                            {% for license in brand.smerpbrandlicense_set.all %}
                                <tr id="license-{{ license.id }}" style="border-bottom: 1px solid #e6e7ec;">
                                    <td colspan="1">
                                        <p class="table_cell content">{{ license.name }}</p>
                                    </td>
                                    <td colspan="1">
                                        <p class="table_cell opr"><img class="thumbnail_image" src="{{ license.img }}" onclick="showBoxImage(this)"/></p>

                                    </td>
                                    <td colspan="1">
                                        <p class="table_cell content">{{ license.get_type_display }}</p>
                                    </td>
                                    <td colspan="1">
                                        <p class="table_cell opr"><a href="{% url "smErp:brand_license" brand.id %}?action=change&license={{ license.id }}">修改</a><a href="javascript:void(0);" data-license="{{ license.id }}" onclick="delete_brand_license(this)">删除</a></p>
                                    </td>
                                </tr>
                            {% endfor %}
                        {% else %}
                                <tr>
                                    <td colspan="4">
                                        <p class="empty_tips">暂无数据</p>
                                    </td>
                                </tr>
                        {% endif %}
                        </tbody>
                    </table>
            </div>

        </div>
    </div>

{% endblock %}

{% block footscript %}
    <script>
        function getCookie(c_name)
        {
            if (document.cookie.length>0)
            {
                c_start=document.cookie.indexOf(c_name + "=");
                if (c_start!=-1)
                {
                    c_start=c_start + c_name.length+1;
                    c_end=document.cookie.indexOf(";",c_start);
                    if (c_end==-1) c_end=document.cookie.length;
                    return unescape(document.cookie.substring(c_start,c_end))
                }
            }
            return ""
        }

        // 删除品牌
        function delete_brand(obj){
            var url = $(obj).data("url");
            layer.confirm('确定要删除此品牌？', {
                btn: ['确定','取消'] //按钮
            }, function(){
                $.ajax({
                    url: url,
                    type:"POST",
                    data:{"action": "delete"},
                    headers:{ "X-CSRFtoken":getCookie("csrftoken")},
                    success:function (data) {
                        console.log(data);
                        if(data.result == 0){
                            // 将表格此项删除
                            layer.msg("删除成功");
                            // 跳转到管理页面
                            window.location.href = "{% url 'smErp:manage' %}";
                        }else{
                            layer.msg(data.reason);
                        }
                }
            });
            }, function(){
                layer.msg('取消删除');
            });
        }

        // 删除品牌证书
        function delete_brand_license(obj){
            var license_id =  $(obj).data("license");
            layer.confirm('确定删除此品牌证书？', {
                btn: ['确定','取消'] //按钮
            }, function(){
                $.ajax({
                    url:"{% url "smErp:brand_license" brand.id %}",
                    type:"POST",
                    data:{"license": license_id, "action": "delete"},
                    headers:{ "X-CSRFtoken":getCookie("csrftoken")},
                    success:function (data) {
                        console.log(data);
                        if(data.result == 0){
                            // 将表格此项删除
                            $("#license-" + license_id).remove();
                            layer.msg("删除成功");
                        }else{
                            layer.msg(data.reason);
                        }
                }
            });
            }, function(){
                layer.msg('取消删除');
            });
        }

        // 弹窗显示图片
        function showBoxImage(obj) {
            var url = $(obj).attr('src');
            //iframe层-父子操作
            layer.open({
                type: 2,
                area: ['800px', '500px'],
                title: '图片：',
                fixed: true, //不固定
                maxmin: true,
                content: url
            });
        };
    </script>
{% endblock %}




